
function SarfFix2:TrinketMenu_PerformSlotSwap(which)
	local slot = which + 13;
	if ( TrinketMenu.CombatQueue[which] ) then
		local texture,name = TrinketMenu.ItemInfo(slot);
		TrinketMenu.EquipTrinketByName(TrinketMenu.CombatQueue[which],slot)
		TrinketMenu.CombatQueue[which] = name;
	end
end

function SarfFix2:TrinketMenu_AttemptToDoSwap()
	-- trinkets can now be swapped after combat/death
	if TrinketMenu.CombatQueue[0] or TrinketMenu.CombatQueue[1] then
		
		SarfFix2:TrinketMenu_PerformSlotSwap(0);
		SarfFix2:TrinketMenu_PerformSlotSwap(1);

		TrinketMenu.UpdateCombatQueue()
	end
end

function SarfFix2.TrinketMenu_OnEventFix()
	
	if (event=="PLAYER_REGEN_ENABLED" or event=="PLAYER_UNGHOST" or event=="PLAYER_ALIVE") and not TrinketMenu.IsPlayerReallyDead() then
		SarfFix2:TrinketMenu_AttemptToDoSwap();
	end
	return SarfFix2.setup.oldTrinketMenu_OnEvent();
end

function SarfFix2:TrinketMenu_DoSwap()
	local oldEvent = event;
	event = "PLAYER_REGEN_ENABLED";
	TrinketMenu.OnEvent()
	even = oldEvent;
end

function SarfFix2.TrinketMenu_OnInitialize()
	if (type(TrinketMenu) ~= "table" ) then
		SarfFix2:PrintError("SarfFix2: TrinketMenu could not be patched (table not found).");
	end
	local func = TrinketMenu.OnEvent;
	if ( type(func) ~= "function" ) then
		SarfFix2:PrintError("SarfFix2: TrinketMenu could not be patched (OnEvent function not found).");
	end
	SarfFix2.setup.oldTrinketMenu_OnEvent = func;
	TrinketMenu.OnEvent = SarfFix2.TrinketMenu_OnEventFix;
	
end

SarfFix2:PatchAddon("TrinketMenu", SarfFix2.TrinketMenu_OnInitialize);